package com.ydd.controller.amidn;

import com.ydd.dto.CatePageQueryDTO;
import com.ydd.dto.YddCateTDO;
import com.ydd.entity.YddCate;
import com.ydd.result.Result;
import com.ydd.service.CateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分类管理
 */

@RestController
@RequestMapping("/ydd_cate")
@Api(tags = "分类相关接口")
@Slf4j
public class CateController {
    @Autowired
    private CateService cateService;
    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增分类")
    public Result<String> save(@RequestBody YddCateTDO yddCateTDO){
        log.info("新增分类：{}", yddCateTDO);
        cateService.save(yddCateTDO);
        return Result.success();
    }

    /**
     * 分页查询套餐列表
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public Result page(CatePageQueryDTO catePageQueryDTO){
        log.info("分页查询套餐列表：{}",catePageQueryDTO);
        return  cateService.catePageQuery(catePageQueryDTO);
    }

    /**
     * 删除分类
     *
     */
    @GetMapping("/del")
    @ApiOperation("删除分类")
    public Result<String> deleteById(Integer id){
        log.info("删除分类：{}",id);
        cateService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改分类
     */
    @PostMapping("/update")
    public Result<String> update(@RequestBody YddCateTDO yddCateTDO){

        return cateService.update(yddCateTDO);
    }


    //回显id
    @GetMapping("/rowInfo")
    @ApiOperation("回显id")
    public Result rowInfo(String id){
        log.info("回显id：{}",id);
        YddCate yddCate = cateService.rowInfo(id);
        return Result.success(yddCate);
    }

    //查询全部
    @GetMapping("/all")
    public Result getAll(){
        log.info("查询全部");
        return cateService.getAll();
    }
}
